package work.parabola.keyboardswitch.util;

import java.math.BigDecimal;

public class BigDecimalUtil {
    public static final BigDecimal ZERO_SCALE_2 = new BigDecimal(0).setScale(2, BigDecimal.ROUND_HALF_UP);

    public static BigDecimal mulInt(BigDecimal a, int b, int scale){
        if(a == null){
            a = new BigDecimal("0").setScale(scale, BigDecimal.ROUND_HALF_UP);
        }
        return a.multiply(new BigDecimal(b)).setScale(scale, BigDecimal.ROUND_HALF_UP);
    }

    public static BigDecimal add(BigDecimal a, BigDecimal b, int scale){
        if(a == null){
            a = new BigDecimal("0").setScale(scale, BigDecimal.ROUND_HALF_UP);
        }
        if(b == null){
            b = new BigDecimal("0").setScale(scale, BigDecimal.ROUND_HALF_UP);
        }
        return a.add(b).setScale(scale, BigDecimal.ROUND_HALF_UP);
    }
}
